//#pragma once
#include<iostream>
#include<assert.h>
using namespace std;

class Date
{
    //友元函数声明
    friend ostream& operator<<(ostream& out,const Date& d);
    friend istream& operator>>(istream& out, Date& d);
public:
    //缺省值只能在声明的地方给，不能和定义同时给
    Date(int year=1900,int month=1,int day=1);
    void print();

    bool CheckDate()
    {
        if(_month<1||_month>12
          ||_day<1||_day>GetMonthDay(_year,_month))
          {
            return false;
          }
          else
          {
            return true;
          }
    }

    int GetMonthDay(int year,int month)
    {
        assert(month>0&&month<13);
        static int monthDayArray[13]={-1,31,28,31,30,31,30,31,31,30,31,30,31};
    
        if(month==2&&(year%4==0&&year%100!=0)||(year%400==0))
        {
            return 29;
        }
        else
        {
            return monthDayArray[month];
        }
    }

    bool operator<(const Date& d);
    bool operator>(const Date& d);
    bool operator<=(const Date& d);
    bool operator>=(const Date& d);
    bool operator==(const Date& d);
    bool operator!=(const Date& d);

    Date& operator+(int day);
    Date& operator+=(int day);

    Date& operator-(int day);
    Date& operator-=(int day);

    Date& operator++();
    Date operator++(int);

    Date& operator--();
    Date operator--(int);

    int operator-(const Date& d);
    //流插入，即输出
    //operator<<(ostream& out);
private:
    int _year;
    int _month;
    int _day;
};

ostream& operator<<(ostream& out,const Date& d);
istream& operator>>(istream& out, Date& d);
